<template>
  <div class="dashboard-page">
    <div class="dashboard-header">
      <h1 class="dashboard-title">控制台</h1>
      <p class="dashboard-subtitle">欢迎使用COKFOOD管理后台</p>
    </div>

    <div class="dashboard-content">
      <!-- 统计卡片区域 -->
      <div class="stats-grid">
        <OverviewCard
          icon="shopping-cart"
          title="今日订单"
          :value="dashboardData.todayOrders"
          :growth="dashboardData.growth.todayOrders"
        />

        <OverviewCard
          icon="user-tie"
          title="总经销商用户数量"
          :value="dashboardData.totalDistributors"
          :growth="dashboardData.growth.totalDistributors"
        />

        <OverviewCard
          icon="users-cog"
          title="总代理数量"
          :value="dashboardData.totalAgents"
          :growth="dashboardData.growth.totalAgents"
        />

        <OverviewCard
          icon="shopping-bag"
          title="产品总数"
          :value="dashboardData.totalProducts"
          :growth="dashboardData.growth.totalProducts"
        />

        <OverviewCard
          icon="coins"
          title="今日付款金额"
          :value="dashboardData.todayPaymentAmount"
          :growth="dashboardData.growth.todayPaymentAmount"
          suffix=" USDT"
        />

        <OverviewCard
          icon="money-bill-wave"
          title="总收入"
          :value="dashboardData.totalRevenue"
          :growth="dashboardData.growth.totalRevenue"
          suffix=" USDT"
        />

        <OverviewCard
          icon="clipboard-list"
          title="待处理提款申请金额"
          :value="dashboardData.pendingWithdrawAmount"
          :growth="dashboardData.growth.pendingWithdrawAmount"
          suffix=" USDT"
        />

        <OverviewCard
          icon="hand-holding-usd"
          title="总提款金额"
          :value="dashboardData.totalWithdrawAmount"
          :growth="dashboardData.growth.totalWithdrawAmount"
          suffix=" USDT"
        />
      </div>

      <!-- 数据概览和最近活动区域 -->
      <div class="dashboard-two-column">
        <!-- 图表区域 -->
        <div class="chart-section">
          <div class="section-header">
            <h2 class="section-title">数据概览</h2>
          </div>
          <SalesTrendChart />
        </div>

        <!-- 最近活动 -->
        <div class="recent-activities-container">
          <RecentActivities />
        </div>
      </div>

      <!-- 最近订单部分 -->
      <div class="recent-orders-section">
        <div class="section-header">
          <h2 class="section-title">订单分布</h2>
        </div>
        <BaseChart
          type="pie"
          title="订单状态分布"
          :series="orderStatusData"
          :categories="orderStatusLabels"
          :showDataLabels="true"
          height="300px"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import OverviewCard from '@/components/admin/dashboard/OverviewCard.vue';
import RecentActivities from '@/components/admin/dashboard/RecentActivities.vue';
import { generateDashboardOverviewData } from '@/utils/adminMock';
import BaseChart from '@/components/admin/charts/BaseChart.vue';
import SalesTrendChart from '@/components/admin/charts/SalesTrendChart.vue';

// 初始化仪表盘数据
const dashboardData = ref(generateDashboardOverviewData());

// 销售数据
// const salesData = ref([...]);
// const salesCategories = ref([...]);

// 订单状态数据
const orderStatusData = ref([44, 55, 13, 33, 22]);
const orderStatusLabels = ref(['待支付', '待发货', '已发货', '已完成', '已取消']);

// 页面加载时获取数据
onMounted(() => {
  // 这里可以替换为实际的API调用
  // 目前使用模拟数据
  dashboardData.value = generateDashboardOverviewData();
});
</script>

<style scoped>
.dashboard-page {
  padding: 20px;
}

.dashboard-header {
  margin-bottom: 24px;
}

.dashboard-title {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  color: #333;
}

.dashboard-subtitle {
  font-size: 14px;
  color: #666;
  margin: 8px 0 0 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.dashboard-two-column {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.recent-activities-container {
  /* 不需要单独设置背景色和阴影，因为RecentActivities组件已包含这些样式 */
  height: 100%; /* 确保高度与图表区域相同 */
  display: flex;
  flex-direction: column;
}

@media (max-width: 1600px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-two-column {
    grid-template-columns: 1fr;
  }

  .recent-activities-container {
    margin-top: 20px; /* 在小屏幕上添加顶部间距 */
  }
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

.chart-section, .recent-orders-section {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: #333;
}

.chart-placeholder, .table-placeholder {
  background-color: #f5f6fa;
  border: 1px dashed #ccc;
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  color: #666;
}
</style>
